import {createWebHashHistory } from "vue-router";
import { createRouter } from "vue-router";
import easyapi from '../api';
const islogin=async function(to,from){
    //获取token
    let token=await sessionStorage.getItem("easytoken");
    //验证token是否有效
    let result=await easyapi.get("/api/checktoken");

    if(!token || result.code!=200){
        return {path:'/login'};
    }
}
const router=createRouter(
{
    history:createWebHashHistory(),
    routes:[
        {path:'/',redirect:'/carrental'},
        {path:'/carrental',component:()=>import("../views/chenggong.vue"),
            children:[{path:'/carlist',component:()=>import("../views/carlist.vue")},
                {path:'/userlist',component:()=>import("../views/customerlist.vue")},
                {path:'/checktablelist',component:()=>import("../views/checktablelist.vue")},
                {path:'/rentalslist',component:()=>import("../views/rentalslist.vue")},
                {path:'/stafflist',component:()=>import("../views/stafflist.vue")},
                {path:'/carsortlist',component:()=>import("../views/carsortlist.vue")},
                {path:'/pieshapedview',component:()=>import("../views/pieshapedview.vue")}
                
            ],beforeEnter:islogin
            
        },
        {path:'/login',component:()=>import("../views/login.vue")}
        
        
    ]

}
);export default router;

